import request from '@/utils/request'
import { MessageBox } from "element-ui";
function add(data) {
  return request({
    url:'/admin/certificate/add',
    method:'post',
    data:data
  }).then(res => {
    MessageBox({
      message: res.message,
      type: 'success',
      duration: 1000
    });
    return res.data;
  })
}

function update(data) {
  return request({
    url:'/admin/certificate/update',
    method:'post',
    data:data
  }).then(res => {
    return res.data;
  })
}
function updateStatus(data) {
  return request({
    url:'/admin/certificate/updateStatus',
    method:'post',
    data:data
  }).then(res => {

    MessageBox({
      message: '修改成功',
      type: 'success',
      duration: 1000
    });

    return res.data;
  })
}



function list(data) {
  return request({
    url:'/admin/certificate/list',
    method:'post',
    data:data
  }).then(res => {
   
    return res.data;

  })
}

/**
 * 
 * @param {} data 没有
 * @returns 
 */
function UpdateShopwindow(data) {
  return request({
    url:'/admin/certificate/list',
    method:'post',
    data:data
  }).then(res => {
   
    return res.data;

  })
}

function mint(data) {

  return request({
    url:'/admin/certificate/mint',
    method:'post',
    data:data
  }).then(res => {

    MessageBox({
      message: res.message,
      type: 'success',
      duration: 1000
    });

    return res.data;
  })
}


function listBySearch(data) {
  let value;

  for (let key in data) {
    value = data[key];
    if (value == null || value == "") {
      delete data[key]; 
    }
  }

  if (null != data.time) {


    data.startTime = data.time[0] / 1000;

    data.endTime = data.time[1] /1000;


  }

  let requestData = {...data};

  delete requestData.time;

  return request({
    url:'/admin/certificate/listBySearch',
    method:'post',
    data:requestData
  }).then(res => {
    return res.data;
  })
}

export {
  add,
  mint,
  updateStatus,
  list,
  update,
  listBySearch,
  UpdateShopwindow
}